package com.distribute;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableGlobalMethodSecurity(prePostEnabled = true)
@ComponentScan(basePackages = {"com.codingapi.tx.*","com.distribute.*"})
@EnableAspectJAutoProxy(proxyTargetClass=true,exposeProxy=true)  // 开启AOP
@EnableTransactionManagement(proxyTargetClass=true) // 开启spring事务管理
public class Config extends WebSecurityConfigurerAdapter {

	@Bean
	public BCryptPasswordEncoder bCryptPasswordEncoder() {
		return new BCryptPasswordEncoder();
	}

	@Autowired
	private DataSource dataSource;
	
    /**
     * 注入
     * LCN的代理连接池
     * @return
     */
    @Bean("transactionManager")
    public PlatformTransactionManager txManager(){
        return new DataSourceTransactionManager(dataSource);
    }
}
